<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台（PHP版）
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码，建议反馈是我们前进的动力
// | 开源版本可自由商用，可去除界面版权logo
// | gitee下载：https://gitee.com/likeshop_gitee/likeadmin
// | github下载：https://github.com/likeshop-github/likeadmin
// | 访问官网：https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------


namespace app\adminapi\controller\room;


use app\adminapi\controller\BaseAdminController;
use app\adminapi\lists\room\RoomHospitalUserExportSeason;
use app\adminapi\lists\room\RoomHospitalUserLists;
use app\adminapi\logic\room\RoomHospitalUserLogic;
use app\adminapi\validate\room\RoomHospitalUserValidate;
use app\common\model\room\RoomHospital;


/**
 * 全院用户关联控制器
 * Class RoomHospitalUserController
 * @package app\adminapi\controller\room
 */
class RoomHospitalUserController extends BaseAdminController {


    /**
     * @notes 获取全院用户关联列表
     * @return \think\response\Json
     * @author likeadmin
     * @date 2024/02/26 16:32
     */
    public function lists() {
        set_time_limit(0);
        ini_set("max_execution_time", 30000);

        return $this->dataLists(new RoomHospitalUserLists());
    }

    /**
     * 打印-住户汇总
     */
    public function print_lists_user_stat() {
        set_time_limit(0);
        ini_set("max_execution_time", 30000);

        return $this->success('', [
            "lists" => (new RoomHospitalUserLists())->print_stat_lists(),
            "keyword" => (new RoomHospital())->getPrintKeywordListUserStat(),
        ], 1, 1);
    }

    /**
     * 打印-住户-设备详情
     */
    public function print_lists_user_device() {
        set_time_limit(0);
        ini_set("max_execution_time", 30000);

        return $this->success('', [
            "lists" => (new RoomHospitalUserLists())->print_lists(),
            "keyword" => (new RoomHospital())->getPrintKeywordListUserDevice(),
        ], 1, 1);
    }

    /**
     * 打印-住户-设备详情-季度
     */
    public function print_lists_user_quarter() {
        set_time_limit(0);
        ini_set("max_execution_time", 30000);

        return $this->success('', [
            "lists" => (new RoomHospitalUserLists())->new_print(),
            "keyword" => (new RoomHospital())->getPrintKeywordListUserDevice(),
        ], 1, 1);
    }

    public function export_print_quarter() {
        set_time_limit(0);
        ini_set("max_execution_time", 30000);

        $room_lists = new RoomHospitalUserLists();

        if ($this->request->param("export") == 2) {
            $fields = [
                "room_name" => "房间名",
                "user_name" => "姓名",

                "d_base_number" => "电表底数",
                "d_reading" => "电表读数",
                "d_use_total" => "用电度数",
                "d_price" => "电单价",
                "d_total_fee" => "总电费",

                "s_base_number" => "水表底数",
                "s_reading" => "水表读数",
                "s_use_total" => "用水度数",
                "s_price" => "水单价",
                "s_total_fee" => "总水费",

                "lift_fee" => "电梯费",
                "second_pressure_fee" => "加压费",

                "time_text" => "月份",
                "room_department" => "科室",
            ];
            $room_lists->setExport('季度打印数据', $room_lists->new_print(), $fields);
        } else {
            $room_lists->fileName = "季度打印数据";
        }
        return $this->dataLists($room_lists);
    }

//    /**
//     * 导出-住户汇总
//     */
//    public function export_lists_user_stat() {
//        return $this->dataLists(new RoomHospitalUserLists());
//    }
//
//    /**
//     * 导出-住户-设备详情
//     */
//    public function export_lists_user_device() {
//        return $this->dataLists(new RoomHospitalUserLists());
//    }

    /**
     * 导出-住户汇总
     */
    public function export_lists_user_stat() {
        $room_lists = new RoomHospitalUserLists();
        if ($this->request->param("export") == 2) {
            $fields = [
                'user_name' => '住户名',
//                'user_mobile' => '手机号',
                'all_d_total_fee' => '总电费',
                'all_s_total_fee' => '总水费',
                'date_time' => '时间',
            ];
            $room_lists->setExport('全院住户汇总', $room_lists->print_stat_lists(), $fields);
        } else {
            $room_lists->setExport('全院住户汇总', [], []);
        }
        return $this->dataLists($room_lists);
    }

    /**
     * 导出-住户-设备详情
     */
    public function export_lists_user_device() {
        $room_lists = new RoomHospitalUserLists();
        if ($this->request->param("export") == 2) {
            $fields = [
                'room_name' => '房间信息',
                'user_name' => '住户名',
//                'user_mobile' => '手机号',

                'd_base_number' => '电表底数',
                'd_reading' => '电表读数',
                'd_use_total' => '用电度数',
                'd_price' => '电单价',
                'd_total_fee' => '总电费',

                's_base_number' => '水表底数',
                's_reading' => '水表读数',
                's_use_total' => '用水度数',
                's_price' => '水单价',
                's_total_fee' => '总水费',

                'lift_fee' => '电梯费',
                'second_pressure_fee' => '二次加压费',
//                'all_total_fee' => '总费用',
                'time_text' => '时间',
            ];
            $room_lists->setExport("全院住户详细", $room_lists->print_lists(), $fields);
        } else {
            $room_lists->setExport('全院住户详细', [], []);
        }
        return $this->dataLists($room_lists);
    }

    public function export_season_stat() {
        return $this->dataLists(new RoomHospitalUserExportSeason());
    }

    public function export_season_device() {
        $room_lists = new RoomHospitalUserExportSeason();
        if ($this->request->param("export") == 2) {
            $fields = [
                'user_name' => '住户名',
//                'user_mobile' => '手机号',
                'room_name' => '房间信息',

//                'd_base_number' => '电表底数',
//                'd_reading' => '电表读数',
                'room_d_use_total' => '用电度数',
//                'd_price' => '电单价',
                'room_d_total_fee' => '总电费',

//                's_base_number' => '水表底数',
//                's_reading' => '水表读数',
                'room_s_use_total' => '用水度数',
//                's_price' => '水单价',
                'room_s_total_fee' => '总水费',

                'room_lift_fee' => '电梯费',
                'room_second_pressure_fee' => '二次加压费',
                'room_all_total_fee' => '总费用',

                'time_text' => '时间',
                'room_department' => '科室',
            ];
//            var_dump($fields);
//            var_dump($room_lists->lists());
//            exit;
            $room_lists->setExport("全院住户详细(季度)", $room_lists->lists(), $fields);
        } else {
            $room_lists->setExport('全院住户详细(季度)', [], []);
        }
        return $this->dataLists($room_lists);
    }

    /**
     * @notes 添加全院用户关联
     * @return \think\response\Json
     * @author likeadmin
     * @date 2024/02/26 16:32
     */
    public function add() {
        $params = (new RoomHospitalUserValidate())->post()->goCheck('add');
        $result = RoomHospitalUserLogic::add($params);
        if (true === $result) {
            return $this->success('添加成功', [], 1, 1);
        }
        return $this->fail(RoomHospitalUserLogic::getError());
    }


    /**
     * @notes 编辑全院用户关联
     * @return \think\response\Json
     * @author likeadmin
     * @date 2024/02/26 16:32
     */
    public function edit() {
        $params = (new RoomHospitalUserValidate())->post()->goCheck('edit');
        $result = RoomHospitalUserLogic::edit($params);
        if (true === $result) {
            return $this->success('编辑成功', [], 1, 1);
        }
        return $this->fail(RoomHospitalUserLogic::getError());
    }


    /**
     * @notes 删除全院用户关联
     * @return \think\response\Json
     * @author likeadmin
     * @date 2024/02/26 16:32
     */
    public function delete() {
        $params = (new RoomHospitalUserValidate())->post()->goCheck('delete');
        RoomHospitalUserLogic::delete($params);
        return $this->success('删除成功', [], 1, 1);
    }


    /**
     * @notes 获取全院用户关联详情
     * @return \think\response\Json
     * @author likeadmin
     * @date 2024/02/26 16:32
     */
    public function detail() {
        $params = (new RoomHospitalUserValidate())->goCheck('detail');
        $result = RoomHospitalUserLogic::detail($params);
        return $this->data($result);
    }


}
